from .app import bot


def judge_event_type(event_type):
    def crn(arg_type):
        def util(cmd, aliases=[], arg_type=arg_type):
            cmds = [cmd] + aliases
            def register_function(func):
                if event_type == 'command':
                    bot.cmd_route[event_type].append([cmds, func, arg_type])
                elif event_type == 'env':
                    if set(cmds) - ('init', 'enable', 'login', 'stop'): # 说明有不属于的
                        print('固定的事件只能是 init | enable | login | stop')
                    else:
                        bot.cmd_route[event_type].append([cmds, func, arg_type])
                else:
                    bot.cmd_route[event_type].append([cmds, func])
            return register_function
        return util
    return crn


on_command = judge_event_type('command')
on_request = judge_event_type('request')
on_notice = judge_event_type('notice')

on_invoke = judge_event_type('invoke')
on_env = judge_event_type('env')